/**
 * 
 */
package org.whereiswally.job.findwally;

import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.whereiswally.model.Wally;
import org.whereiswally.net.picturerepository.PictureRepository;
import org.whereiswally.net.picturerepository.imp.PicasaPictureRepository;
import org.whereiswally.test.WallyConstantsTest;

/**
 * Clase encargada de proveer URI de PicureRepository para ser procesada por los
 * nodos
 * 
 * @author LGIAVEDO
 * 
 */
public class URIDataProvider implements org.jppf.task.storage.DataProvider,
	Serializable {

    public static final String NEXT_URI = "nextURI";
    public static final String WALLY = "wally";

    private Wally wally;

    private List data = new ArrayList();

    public URIDataProvider() {
	wally = new Wally();

	wally.addFace(new File("resource/faces/wally_a/jpg/ID01_001.jpg")
		.toURI());

	try {
	    data.add(new PicasaPictureRepository(new URI(
		    WallyConstantsTest.WALLY_ALBUM)));
	    data.add(new PicasaPictureRepository(new URI(
		    WallyConstantsTest.WALLY_ALBUM)));
	} catch (URISyntaxException e) {
	    e.printStackTrace();
	}

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.jppf.task.storage.DataProvider#getValue(java.lang.Object)
     */
    @Override
    public Object getValue(Object arg0) throws Exception {

	if (NEXT_URI.equals(arg0)) {
	    if (data.size() > 0) {
		PictureRepository pr = (PictureRepository) data.get(0);
		data.remove(0);
		return pr;
	    }
	}
	if (WALLY.equals(arg0)) {
	    return wally;
	}

	return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.jppf.task.storage.DataProvider#setValue(java.lang.Object,
     * java.lang.Object)
     */
    @Override
    public void setValue(Object arg0, Object arg1) throws Exception {
	// data.put(arg0, arg1);

    }

}
